﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.Data;
using System.Text;

public partial class MrjSaleRpt : ExtBaseRpt
{
    mrjapp mrj = new mrjapp();
    string mid;
    protected void Page_Load(object sender, EventArgs e)
    {
        mid = Request.Params["mid"];
        if (!X.IsAjaxRequest)
        {
            InsActLog(mid, "浏览");
            this.txtdaybdate.Text = DateTime.Now.ToString("yyyy-MM-dd");
            //BuildGridPanel(this.GridPanel1, mid, Session["UserID"].ToString());
            this.comShop.GetStore().DataSource = mydb.DM_GetDateSet("select shopid,shopname from V_ShopList");
            txtdayoperation.GetStore().DataSource = mydb.DM_GetDateSet("select distinct OperationAreaName from V_ShopList");
            txtdaybigarea.GetStore().DataSource = mydb.DM_GetDateSet("select distinct BigAreaName from V_ShopList");
            txtdayarea.GetStore().DataSource = mydb.DM_GetDateSet("select distinct AreaName from V_ShopList");
        }
    }
    protected void BtnQureyUser(object sender, DirectEventArgs e)
    {
        string str = StrSplit(this.selectshop.Text);
        string edate;
        if (Convert.ToDateTime(txtdayedate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            edate = "";
        else
            edate = txtdayedate.Text;
        string sql = "KM_MrjDaySale_DayTB_Rpt '" + Convert.ToDateTime(txtdaybdate.Text).ToString("yyyy-MM-dd") + "','" + edate
            + "','" + txtdayoperation.Text + "','" + txtdaybigarea.Text + "','" + txtdayarea.Text + "','" + str + "','"+txtdayshopname.Text+"','"+Session["UserID"]+"'";
        this.Store1.DataSource = db.DM_GetDateSet(sql);
        this.Store1.DataBind();
        //QueryData(this.Store1, mid, sql);
    }
    protected void BtnQureyUser2(object sender, DirectEventArgs e)
    {
        if (txtweek.Text == "" && Convert.ToDateTime(txtbdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
        {
            ShowBox("请输入日期查询条件！");
            return;
        }
        if (txtweek.Text != "" && Convert.ToDateTime(txtbdate.Text) != Convert.ToDateTime("0001-01-01 00:00:00"))
        {
            ShowBox("如果按周查询，请删除自定义日期！");
            return;
        }
        string str = StrSplit(this.selectshop.Text);
        string bdate,edate,ubdate,uedate;
        if (Convert.ToDateTime(txtbdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            bdate = "";
        else
            bdate = txtbdate.Text;
        if (Convert.ToDateTime(txtedate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            edate = "";
        else
            edate = txtedate.Text;
        if (Convert.ToDateTime(txtubdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            ubdate = "";
        else
            ubdate = txtubdate.Text;
        if (Convert.ToDateTime(txtuedate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            uedate = "";
        else
            uedate = txtuedate.Text;
        string sql = "KM_MrjDaySale_MonthTB_Rpt '" + bdate + "','" + edate + "','" + ubdate + "','" + uedate + "','"+txtweek.Text+"','"+txtmonth.Text+"','" 
            + txtdayoperation.Text + "','" + txtdaybigarea.Text + "','" + txtdayarea.Text + "','" + str + "','" + txtdayshopname.Text + "','"+Session["UserID"]+"'";
        this.Store4.DataSource = db.DM_GetDateSet(sql);
        this.Store4.DataBind();
        //QueryData(this.Store1, mid, sql);
    }
    protected void BtnQureyUser3(object sender, DirectEventArgs e)
    {
        if (txtmonth.Text == "" && Convert.ToDateTime(txtbdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
        {
            ShowBox("请输入日期查询条件！");
            return;
        }
        if (txtmonth.Text != "" && Convert.ToDateTime(txtbdate.Text) != Convert.ToDateTime("0001-01-01 00:00:00"))
        {
            ShowBox("如果按周查询，请删除自定义日期！");
            return;
        }
        string str = StrSplit(this.selectshop.Text);
        string bdate, edate, ubdate, uedate;
        if (Convert.ToDateTime(txtbdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            bdate = "";
        else
            bdate = txtbdate.Text;
        if (Convert.ToDateTime(txtedate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            edate = "";
        else
            edate = txtedate.Text;
        if (Convert.ToDateTime(txtubdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            ubdate = "";
        else
            ubdate = txtubdate.Text;
        if (Convert.ToDateTime(txtuedate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            uedate = "";
        else
            uedate = txtuedate.Text;
        string sql = "KM_MrjDaySale_MonthTB_Rpt '" + bdate + "','" + edate + "','" + ubdate + "','" + uedate + "','" + txtweek.Text + "','" + txtmonth.Text + "','"
            + txtdayoperation.Text + "','" + txtdaybigarea.Text + "','" + txtdayarea.Text + "','" + str + "','" + txtdayshopname.Text + "','"+Session["UserID"]+"'";
        this.Store2.DataSource = db.DM_GetDateSet(sql);
        this.Store2.DataBind();
        //QueryData(this.Store1, mid, sql);
    }
    protected void GetBigArea(object sender, DirectEventArgs e)
    {
        txtdaybigarea.GetStore().DataSource = mydb.DM_GetDateSet("select distinct BigAreaName from V_ShopList where OperationAreaName ='"+txtdayoperation.Value+"'");
        this.Store_BigAreaName.DataBind();
    }
    protected void GetArea(object sender, DirectEventArgs e)
    {
        txtdayarea.GetStore().DataSource = mydb.DM_GetDateSet("select distinct AreaName from V_ShopList where BigAreaName ='"+txtdaybigarea.Value+"'");
        this.Store_AreaName.DataBind();
    }
    protected void GetShop(object sender, DirectEventArgs e)
    {
        this.comShop.GetStore().DataSource = mydb.DM_GetDateSet("select shopid,shopname from V_ShopList where AreaName='"+txtdayarea.Value+"'");
        this.Store_Shop.DataBind();
    }
    protected void RefreshDataSet(object sender, StoreReadDataEventArgs e)
    {
        BtnQureyUser(null,null);
    }
    protected void Store1_Submit(object sender, StoreSubmitDataEventArgs e)
    {
        //导出EXCEL
        ExtGridToExcel(mid,"xls",e.Xml,this.Response,"每人计零售分析(日)");
    }
    protected void Store2_Submit(object sender, StoreSubmitDataEventArgs e)
    {
        //导出EXCEL
        ExtGridToExcel(mid, "xls", e.Xml, this.Response, "每人计零售分析(周)");
    }
    protected void Store3_Submit(object sender, StoreSubmitDataEventArgs e)
    {
        //导出EXCEL
        ExtGridToExcel(mid, "xls", e.Xml, this.Response, "每人计零售分析(月)");
    }
}